package net.itbaiyang.pattern.factory;

import net.itbaiyang.pattern.enums.SmsTypeEnum;
import net.itbaiyang.pattern.sms.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:sms-services.xml")
public class SmsServiceFactory {

    @Autowired
    private ApplicationContext context;

    public SmsService getSmsService(String type) {
        SmsTypeEnum smsType = SmsTypeEnum.fromString(type);
        return context.getBean(smsType.getBeanName(), SmsService.class);
    }
}
